package com.example.llm.sgg.sgglangchain.controller;

import com.example.llm.sgg.sgglangchain.assistant.StreamXiaozhiAgent;
import com.example.llm.sgg.sgglangchain.assistant.XiaozhiAgent;
import com.example.llm.sgg.sgglangchain.dto.XiaozhiAgentRequestDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.time.Duration;

@RestController
@RequestMapping("/xiaozhiAgent")
@Tag(name = "小智医疗智能体")
@Slf4j
public class XiaozhiAgentController {

    @Autowired
    private XiaozhiAgent xiaozhiAgent;

    @Operation(summary = "小智医疗智能体对话接口")
    @PostMapping("/chat")
    public String chat(@Validated @RequestBody XiaozhiAgentRequestDTO requestDTO) {
        return xiaozhiAgent.chat(requestDTO.getMemoryId(), requestDTO.getMessage());
    }

    @Autowired
    private StreamXiaozhiAgent streamXiaozhiAgent;

    @Operation(summary = "[SSE]小智医疗智能体对话接口")
    @PostMapping(value = "/sseChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> sseChat(@Validated @RequestBody XiaozhiAgentRequestDTO requestDTO) {
        return streamXiaozhiAgent.chat(requestDTO.getMemoryId(), requestDTO.getMessage());
    }
}